package main

import (
	context "golang.org/x/net/context"
	"log"
	"time"

	pb "grpc-test/pb"

	"google.golang.org/grpc"
)

const (
	address = "localhost:9010"
)

func main() {
	conn, err := grpc.Dial(address, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
	c := pb.NewGreeterClient(conn)
	ctx := context.Background()
	// r, err := c.Add(ctx, &pb.AddRequest{1, 0})
	// if err != nil {
	// 	pp.Println(err)
	// 	log.Panicln(err)
	// }
	// log.Println("ans", r.C)
	ctx2, _ := context.WithTimeout(ctx, time.Second*10)
	r, err := c.StreamHello(ctx2, &pb.StreamHelloRequest{Start: 1, End: 10, Step: 10})
	if err != nil {
		log.Panicln(err)
	}
	for {
		if s, err := r.Recv(); err != nil {
			log.Println("err", err)
			break
		} else {
			log.Println("recv", s)
		}
	}
	log.Println("ok")
}
